package my.jwds.p1109;

import com.alibaba.fastjson.JSONObject;

import java.util.Arrays;

public class CorpFlightBookings {

    public static void main(String[] args) {

        CorpFlightBookings obj = new CorpFlightBookings();



        int [][] bookings = JSONObject.parseObject("[[1,2,10],[2,3,20],[2,5,25]]",int [][].class);
        int n = 5;




        long start = System.currentTimeMillis();
        System.out.println(Arrays.toString(obj.corpFlightBookings(bookings,n)));
        System.out.println("运行时间:" + (System.currentTimeMillis() - start));
    }

    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[]c = new int[n+1];
        for (int[] booking : bookings) {
            add(c,booking[0]-1,booking[1]-1,booking[2]);
        }

        int []res = new int[n];
        res[0] = c[0];
        for (int i = 1; i < n; i++) {
            res[i] = res[i-1] + c[i];
        }
        return res;

    }

    void add(int[]c,int l,int r,int seats){
        c[l]+=seats;
        c[r+1] -= seats;
    }
}